package com.project_doctor.controller;

import com.project_doctor.pojo.dto.PermissionDTO;
import com.project_doctor.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权限控制器
 */
@RestController
@RequestMapping("/permission")
@CrossOrigin
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 获取所有权限菜单（树形结构）
     */
    @GetMapping("/menu")
    public ResponseEntity<List<PermissionDTO>> getMenuPermissions() {
        List<PermissionDTO> permissions = permissionService.getAllPermissions();
        return ResponseEntity.ok(permissions);
    }

    /**
     * 获取用户权限菜单（根据用户角色）
     * 暂时返回所有权限，后续可根据用户角色过滤
     */
    @GetMapping("/user-menu/{userId}")
    public ResponseEntity<List<PermissionDTO>> getUserMenuPermissions(@PathVariable Long userId) {
        // TODO: 根据用户ID获取用户角色权限
        List<PermissionDTO> permissions = permissionService.getAllPermissions();
        return ResponseEntity.ok(permissions);
    }

    /**
     * 获取所有权限列表
     */
    @GetMapping("/list")
    public ResponseEntity<List<PermissionDTO>> getAllPermissions() {
        List<PermissionDTO> permissions = permissionService.getAllPermissions();
        return ResponseEntity.ok(permissions);
    }
}